package 第九周.homework;
//Author:☆♢
/*创建一个异常类，其作用是发现字符串中包含太多字符时抛出异常。
在程序的main方法中读取输入的字符串，直到输入“Done”为止。
如果输入的字符串过长（多于20个字符），则抛出异常。允许抛出的异常终止程序。*/
import java.util.Scanner;
 public class  pp11_1{
     //Creates an expection object and possible throws it.
     public static void main(String []args) throws StringTooLongExpection {
         final int NUM = 20;

         Scanner scan = new Scanner(System.in);

         StringTooLongExpection problem = new StringTooLongExpection("The String have too many character.");

         System.out.println("Enter a string which character numbers Less than" + NUM);
         String string = scan.nextLine();
         if(string.length()>NUM)
             throw problem;
         if(string.substring (string.length()-4,string.length()).equals("Done"))
             System.out.println("End of the method.");//may never reach.
     }
}
